﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace InfoPick.Lib.DataProvider
{
    public class LogFileProvider : DataProviderDecorator
    {
        //临时目录
        private string dir;

        //mgw文件地址
        private string mgwFile;

        //msc文件地址
        private string mscFile;


        public LogFileProvider(string dir, IDataProvider provider)
            : base(provider)
        {
            this.dir = dir;

            //临时目录
            string date = DateTime.Now.ToString("yyyyMMddHHmmss");
            this.mgwFile = getFullPath(date, "mgw");
            this.mscFile = getFullPath(date, "msc");
        }



        public override bool Begin()
        {
            return base.Begin();
        }

        public override void Complete()
        {
            base.Complete();

        }

        private string getFullPath(string dateStr, string file)
        {
            string fullPath = string.Empty;
            if (dir.EndsWith("\\"))
                fullPath = string.Format("{0}{1}\\{2}.txt", dir, dateStr, file);
            else
                fullPath = string.Format("{0}\\{1}\\{2}.txt", dir, dateStr, file);

            return fullPath;
        }

        private string writeLog(string key, string contents)
        {
            string file = string.Empty;
            if (dict[key] == "mgw")
                file = mgwFile;
            if (dict[key] == "msc")
                file = mscFile;
            if (!string.IsNullOrEmpty(file))
            {
                FileInfo fi = new FileInfo(file);

                if (!fi.Directory.Exists)
                {
                    Directory.CreateDirectory(fi.DirectoryName);
                }
                File.AppendAllText(file, contents + "\r\n\r\n\r\n");
            }
            return contents;
        }

        

        public override string GetTdmiuList()
        {
            return writeLog("TDMIU", provider.GetTdmiuList());
        }

        public override string GetE32List()
        {
            return writeLog("E32", provider.GetE32List());
        }

        public override string GetS2lList()
        {
            return writeLog("S2L", provider.GetS2lList());
        }

        public override string GetEpiList()
        {
            return writeLog("EPI", provider.GetEpiList());
        }

        public override string GetCsuList()
        {
            return writeLog("CSU", provider.GetCsuList());
        }

        public override string GetN7LNKALLList()
        {
            return writeLog("N7LNKALL", provider.GetN7LNKALLList());
        }

        public override string GetAIETKCList()
        {
            return writeLog("AIETKC", provider.GetAIETKCList());
        }

        public override string GetN7TKCList()
        {
            return writeLog("N7TKC", provider.GetN7TKCList());
        }

        public override string GetAIETGList()
        {
            return writeLog("AIETG", provider.GetAIETGList());
        }

        public override string GetN7LNKList()
        {
            return writeLog("N7LNK", provider.GetN7LNKList());
        }


        public override string GetMTP2LNKAllList()
        {
            return writeLog("MTP2LNK", provider.GetMTP2LNKAllList());
        }

        public override string GetMTP2LNKList(int key)
        {
            return writeLog("MTP2LNK", provider.GetMTP2LNKList(key));
        }

        public override string GetCLKSRCList()
        {
            return writeLog("CLKSRC", provider.GetCLKSRCList());
        }


    }
}
